/**
 * 
 */
package com.shiplanet.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.shiplanet.entity.Category;
import com.shiplanet.entity.Post;
import com.shiplanet.service.CategoryService;
import com.shiplanet.service.PostService;

/**
 * @author joesong
 *
 */
@Controller
public class IndexAction extends ActionSupport{
	private static final long serialVersionUID = 1L;

	@Resource
	private CategoryService categoryService;
	
	@Resource
	private PostService postService;
	
	public List<Category> categoryList;
	
	public Map<Integer, String> categoryMap;
	
	public List<Category> popularCategories;
	
	public List<Post> featuredPosts;
	
	public String initiate() {
		
		categoryMap = categoryService.getCategoryNameMap(false, false);	
		
		categoryList = categoryService.findRootCategories();
		
		popularCategories = categoryService.findPopularCategories();
		
		featuredPosts = postService.findFeaturedPost();		
		
		return "homepage";
	}

	public List<Category> getCategoryList() {
		return categoryList;
	}

	public Map<Integer, String> getCategoryMap() {
		return categoryMap;
	}

	public List<Category> getPopularCategories() {
		return popularCategories;
	}

	public List<Post> getFeaturedPosts() {
		return featuredPosts;
	}

	public void setCategoryList(List<Category> categoryList) {
		this.categoryList = categoryList;
	}

	public void setCategoryMap(Map<Integer, String> categoryMap) {
		this.categoryMap = categoryMap;
	}

	public void setPopularCategories(List<Category> popularCategories) {
		this.popularCategories = popularCategories;
	}

	public void setFeaturedPosts(List<Post> featuredPosts) {
		this.featuredPosts = featuredPosts;
	}
}
